package org.nf.order.api;

import org.nf.order.dao.OrderDao;
import org.nf.order.dao.impl.OrderDaoImpl;
import org.nf.order.model.Order;
import org.nf.order.service.OrderService;
import org.nf.order.service.impl.OrderServiceImpl;
import org.nf.order.vo.PageVO;
import org.nf.order.vo.ResultVO;
import org.nf.web.annotation.Model;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

import java.util.List;


public class OrderController extends BaseController {
    private OrderService orderService = new OrderServiceImpl();
    private OrderDao orderDao = new OrderDaoImpl();

    @RequestMapping("/addOrder")
    public View addOrder(@Model Order order) {

        orderDao.insertOrder(order);
        ResultVO vo = success(orderDao);
        vo.setMessage("添加成功");
        vo.setCode(200);
        return new JsonView(vo);
    }

    @RequestMapping("/api/selectByName")
    public View selectByName(@RequestParam("productName") String uId) {
        orderDao.select(uId);
        ResultVO vo = success(orderDao);
        vo.setCode(200);
        vo.setMessage("查询成功");
        return new JsonView(vo);

    }

    @RequestMapping("/api/listOrder")
    public View listOrder(@RequestParam("page") int page,
                         @RequestParam("limit") int limit) {

        PageVO<List<Order>> pageVO = orderService.listOrder(page,limit);
        //创建JSON视图响应
        return new JsonView(pageVO);
    }



    @RequestMapping("/api/updateOrder")
    public View updateOrder(@Model Order order){
        orderDao.updateOrder(order);
        ResultVO vo = success(orderDao);
        vo.setData(200);
        vo.setMessage("修改成功");
        return new JsonView(vo);
    }



}










